package com.joyoung.datarespository;

import android.content.Context;
import android.util.Log;

import com.joyoung.cons.BaseResult;
import com.joyoung.sdk.info.UserConfirmData;
import com.joyoung.sdk.utils.encryptdecryptutil.MakeUUID;

import java.io.File;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

import static com.joyoung.cons.URLGenerateUtil.noSessionParma;
import static com.joyoung.cons.URLGenerateUtil.noSessionUrl;

/**
 * Created by wubin on 2017\7\19 0019.
 */

public class JYHttpDS1 {

    private String json;
    private final String TAG = "JYHttpDS1";

    public interface JoyoungCallBack<T> {
        void Success(T t);

        void failed(String msg);
    }


    public void login(String userName, String password,
                      final JoyoungCallBack<BaseResult<UserConfirmData>> callBack) {
        try {
            json = new LoginBuilder()
                    .uname(userName)
                    .passwd(MakeUUID.base64Encode(password.getBytes()))
                    .build();

            String baseUrl = "/rms/v1/app/login?action=login";
            String rmsUrl = noSessionUrl(baseUrl, json);
            String param = noSessionParma(json);

            RetrofitSingleton.getINSTANCE().getRmsJoyoungApi().login(rmsUrl, param)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Action1<BaseResult<UserConfirmData>>() {
                        @Override
                        public void call(BaseResult<UserConfirmData> result) {
                            callBack.Success(result);
                        }
                    }, new Action1<Throwable>() {
                        @Override
                        public void call(Throwable throwable) {
                            callBack.failed(throwable.getMessage());
                        }
                    });
        } catch (Exception e) {
            return;
        }
    }
}
